00001 // Emacs Mode Line: -*- Mode:c++;-*- 00002 /* 00003 * Copyright (c) 2013 Battelle Memorial Institute 00004 * Licensed under modified BSD License. A copy of this license can be found 00005 * in the LICENSE file in the top level directory of this distribution. 00006 */ 00007 // ------------------------------------------------------------- 00008 /** 00009 * @file cmd_line.hpp 00010 * @author Bruce Palmer 00011 * @date 2019-05-24 09:25:03 d3g293 00012 * 00013 * @brief 00014 * This utility is designed to support parsing of command line arguments coming 00015 * in via the standard (int argv, char **argc) arguments of main. This module 00016 * ignores the first argument (the program name). The number of arguments 00017 * returned by the class is argv-1. 00018 * 00019 */ 00020 00021 // ------------------------------------------------------------- 00022 00023 #ifndef _cmd_line_hpp_ 00024 #define _cmd_line_hpp_ 00025 00026 #include <string> 00027 #include <vector> 00028 #include "gridpack/utilities/string_utils.hpp" 00029 00030 namespace gridpack { 00031 namespace parser { 00032 00033 // ------------------------------------------------------------- 00034 // class CmdLineParser 00035 // ------------------------------------------------------------- 00036 class CmdLineParser { 00037 public: 00038 00039 /** 00040 * Default constructor 00041 * @param argv standard argv from main 00042 * @param argc standard argc from main 00043 */ 00044 CmdLineParser(int argv, char** argc); 00045 00046 /** 00047 * Default destructor 00048 */ 00049 ~CmdLineParser(void); 00050 00051 /** 00052 * Return the total number of tokens found in command line arguments. This is 00053 * one less than the original argv 00054 * @return number of command line tokens 00055 */ 00056 int numCmdTokens(); 00057 00058 /** 00059 * Return the requested token (by index) 00060 * @param idx index of requested token 00061 * @return requested token 00062 */ 00063 std::string getToken(int idx); 00064 00065 /** 00066 * Get the token after the token represented by the string. The token given in 00067 * the argument will match any token that contains the same first characters 00068 * as the input string 00069 * @param key string that is used to match token in internal list 00070 * @return next token in command list after key 00071 */ 00072 std::string getTokenAfter(const char *key); 00073 00074 private: 00075 00076 // Number of tokens in command line arguments 00077 int p_argv; 00078 00079 // Individual tokens in command line arguments 00080 std::vector<std::string> p_argc; 00081 }; 00082 00083 00084 } // namespace gridpack 00085 } // namespace parser 00086 00087 #endif